local db = TUNING.MOD_WEBBER_THE_TRAINER.webbert_soul

local lang = STRINGS.MOD_WEBBER_THE_TRAINER.webbert_soul_rewards
---@class webbert_soul_rewards
---@field label string
---@field hint string
---@field fn_calccost fun(times:integer):integer # 计算花费
---@field fn_buy fun(player:ent)|nil # 购买
---@field fn_save (fun(player:ent):table)|nil # 某些情况 需要再组件里额外存一些东西
---@field fn_load (fun(player:ent,data:table))|nil # 同上 

---@type webbert_soul_rewards[]
local rewards = {
    {
        label = lang[1][1],
        hint = lang[1][2],
        fn_calccost = function (times)
            return math.floor(20 * (times + 1) ^ 1.1)
        end,
        fn_buy = function (player)
            if player.components.health then
                player.components.health.maxhealth = player.components.health.maxhealth + db.buy.buy_1_maxhp
                player.components.health:DoDelta(0)
            end
        end,
        fn_save = function (player)
            local data = {}
            if player.components.health then
                data.hp_percent = player.components.health:GetPercent()
            end
            return data
        end,
        fn_load = function (player, data)
            if data and data.hp_percent and player.components.health and player.components.webbert_soul then
                player.components.health.maxhealth = player.components.health.maxhealth + db.buy.buy_1_maxhp * player.components.webbert_soul['buy_times_1']
                player.components.health:SetPercent(data.hp_percent)
            end
        end
    },
    {
        label = lang[2][1],
        hint = lang[2][2],
        fn_calccost = function (times)
            return math.floor(200 * math.log(times + 1) + 10)
        end,
        fn_buy = function (player)
            if player.components.hunger then
                player.components.hunger.max = player.components.hunger.max + db.buy.buy_2_hunger
                player.components.hunger:DoDelta(0)
            end
        end,
        fn_save = function (player)
            local data = {}
            if player.components.hunger then
                data.hunger_percent = player.components.hunger:GetPercent()
            end
            return data
        end,
        fn_load = function (player, data)
            if data and data.hunger_percent and player.components.health then
                player.components.hunger.max = player.components.hunger.max + db.buy.buy_2_hunger * player.components.webbert_soul['buy_times_2']
                player.components.health:SetPercent(data.hunger_percent)
            end
        end
    },
    {
        label = lang[3][1],
        hint = lang[3][2],
        fn_calccost = function (times)
            return math.floor(10 * (times + 1) ^ 1.6)
        end,
    },
    {
        label = lang[4][1],
        hint = lang[4][2],
        fn_calccost = function (times)
            return math.floor(30 * (times + 1) ^ 1.5)
        end,
        fn_buy = function (player)
            if player.components.webber_the_trainer_dmg_modifier and player.components.webbert_soul then
                local buy4 = player.components.webbert_soul['buy_times_4'] or 0
                player.components.webber_the_trainer_dmg_modifier:ModifierNormal("planar",'add','webbert_soul',buy4,'buy_times_4')
            end
        end,
        fn_load = function (player, data)
            if player.components.webber_the_trainer_dmg_modifier and player.components.webbert_soul then
                local buy4 = player.components.webbert_soul['buy_times_4'] or 0
                player.components.webber_the_trainer_dmg_modifier:ModifierNormal("planar",'add','webbert_soul',buy4,'buy_times_4')
            end
        end
    },
    {
        label = lang[5][1],
        hint = lang[5][2],
        fn_calccost = function (times)
            return math.floor(5 * (times + 1) ^ 2)
        end,
    },
    {
        label = lang[6][1],
        hint = lang[6][2],
        fn_calccost = function (times)
            return math.floor(6 * (times + 1) ^ 2)
        end,
    },
    {
        label = lang[7][1],
        hint = lang[7][2],
        fn_calccost = function (times)
            return math.floor(4 * (times + 1) ^ 1.5)
        end,
        fn_buy = function (player)
            local buy7 = player.components.webbert_soul and player.components.webbert_soul['buy_times_7'] or 0
            local mult = math.max(0,1-buy7*db.buy.buy_7_burnrate)
            if player.components.hunger then
                player.components.hunger.burnratemodifiers:SetModifier('webbert_soul',mult,'buy_times_7')
            end
            if player.components.foodaffinity then
                for _,v in pairs(FOODTYPE) do
                    local _mult = mult * .8
                    if v == FOODTYPE.VEGGIE then
                        _mult = _mult * .5
                    end
                    player.components.foodaffinity:AddFoodtypeAffinity(v,_mult)
                end
            end
        end,
        fn_load = function (player, data)
            local buy7 = player.components.webbert_soul and player.components.webbert_soul['buy_times_7'] or 0
            local mult = math.max(0,1-buy7*db.buy.buy_7_burnrate)
            if player.components.hunger then
                player.components.hunger.burnratemodifiers:SetModifier('webbert_soul',mult,'buy_times_7')
            end
            if player.components.foodaffinity then
                for _,v in pairs(FOODTYPE) do
                    local _mult = mult * .8
                    if v == FOODTYPE.VEGGIE then
                        _mult = _mult * .5
                    end
                    player.components.foodaffinity:AddFoodtypeAffinity(v,_mult)
                end
            end
        end
    },
    {
        label = lang[8][1],
        hint = lang[8][2],
        fn_calccost = function (times)
            return math.floor(3 * (times + 1) ^ 2.5 + 300)
        end,
    },
    {
        label = lang[9][1],
        hint = lang[9][2],
        fn_calccost = function (times)
            return math.floor(300 * math.log(times + 1) + 10)
        end,
    },
    {
        label = lang[10][1],
        hint = lang[10][2],
        fn_calccost = function (times)
            return math.floor(90 * (times + 1) ^ 2)+500
        end,
    },
}


return rewards